cmake_minimum_required(VERSION 3.1...3.20)

project(cpp_std LANGUAGES CXX)

# 设置 C++ 标准为 C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#设置可执行程序路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)


# print custom message depending on the operating system
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  message(STATUS "Configuring on/for Linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  message(STATUS "Configuring on/for macOS")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  message(STATUS "Configuring on/for Windows")
elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  message(STATUS "Configuring on/for IBM AIX")
else()
  message(STATUS "Configuring on/for ${CMAKE_SYSTEM_NAME}")
endif()


#include(CheckCXXCompilerFlag)
#CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
#CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
#if(COMPILER_SUPPORTS_CXX11)
        #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#elseif(COMPILER_SUPPORTS_CXX0X)
        #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
#else()
     #message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
#endif()

# set(CMAKE_C_COMPILER gcc)
# set(CMAKE_CXX_COMPILER g++)

# if(NOT CMAKE_BUILD_TYPE)
#     set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
# endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

#-DENABLE_COVERAGE=ON
# set(CMAKE_CXX_FLAGS 
#         "${CMAKE_CXX_FLAGS} -std=c++11 -DDEBUG -DFMT_HEADER_ONLY -DXLOG_HEADER_ONLY -DXLOG_ACTIVE_LEVEL=0 -g -O0 -pthread")
#-fprofile-arcs -ftest-coverage

# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -std=c++11 -DDEBUG -g -O0 -pthread")
# set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})

message(STATUS "C flags, Debug configuration: ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "C flags, Release configuration: ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "C flags, Release configuration with Debug info: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
message(STATUS "C flags, minimal Release configuration: ${CMAKE_C_FLAGS_MINSIZEREL}")
message(STATUS "C++ flags, Debug configuration: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "C++ flags, Release configuration: ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "C++ flags, Release configuration with Debug info : ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS "C++ flags, minimal Release configuration: ${CMAKE_CXX_FLAGS_MINSIZEREL}")

# 添加一个模块，并且将编译好库文件放置在 build/lib 目录
add_subdirectory(math lib)

# option(TIME_CLOCK_COARSE 
#         "linux首选获取时间函数：clock_gettime()，不追求绝对准确，而担心系统调用消耗的，可以尝试" 
#         ON)

# foreach(USER_OPTION
#         TIME_CLOCK_COARSE)
#         if (${USER_OPTION})
#                 message(STATUS "add definition: ${USER_OPTION}")
#                 add_definitions(-D${USER_OPTION})
#         endif()
# endforeach(USER_OPTION)

include_directories(
        .
)
# if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# include_directories(
#         /usr/local/include/hiredis
#         ./dep
# )
# endif()

#add_subdirectory(dep)


# aux_source_directory(. DIR_SRCS)
# aux_source_directory(./math DIR_SRCS)
#aux_source_directory(./tests DIR_SRCS)
# aux_source_directory(./event DIR_SRCS)
# aux_source_directory(./define DIR_SRCS)
# aux_source_directory(./thread DIR_SRCS)
# aux_source_directory(./loop DIR_SRCS)
# aux_source_directory(./util DIR_SRCS)
# aux_source_directory(./hasio DIR_SRCS)
# aux_source_directory(./common/time DIR_SRCS)
# aux_source_directory(./game DIR_SRCS)
# aux_source_directory(./game/manager DIR_SRCS)
# aux_source_directory(./log DIR_SRCS)
# aux_source_directory(./redis DIR_SRCS)
# 链接 math
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")

if(USE_MATH_LIBRARY)
        # 添加一个模块，并且将编译好库文件放置在 build/lib 目录
        add_subdirectory(math lib)
else()
        aux_source_directory(./math DIR_SRCS)
endif()

add_executable(${PROJECT_NAME} ${DIR_SRCS})

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(${PROJECT_NAME} /usr/local/lib/libhiredis.so)
endif()

if(USE_MATH_LIBRARY)
        target_link_libraries(${PROJECT_NAME} math)
endif()

#测试程序
add_subdirectory(tests/src)
